// 权限控制
import router from './router'
import store from './store'

import 'nprogress/nprogress.css'
// 白名单
const writeList = [
  '/login',
  '/404'
]
// 路由前置守卫
router.beforeEach((to, from, next) => {
  const token = store.state.user.token

  if (token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (writeList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
// 路由后置守卫
router.afterEach((to, from) => {
  // NProgress.done()
})
